import request from "@/utils/axios";
// 假数据
import _data from "./data.json";

// 获取测试用例的 左侧菜单
export function CaseMenuList(params) {
  return request.post("/sysPackage/listExampleRescources", params);
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 1,
        msg: "成功",
        data: _data.testCaseName,
      });
    }, 1000);
  });
}
// 获取测试用例的 右侧table数据
export function AdminCaseDataList(params) {
  return request.post("/example/queryTestExampleList", params);

  const child = _data.testCaseChildren.find(
    (e) => e.parentId === data.parentId
  );
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 1,
        msg: "成功",
        data: child,
      });
    }, 1000);
  });
}
// 获取 用例的 优先级列表
export function PriorityAllList() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 1,
        msg: "成功",
        data: _data.priorityList,
      });
    }, 1000);
  });
}

// 获取用例详情
export function ObtainCaseDetail(params) {
  return request.get("/example/getTestExampleInfo", { params });

  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 1,
        msg: "成功",
        data: _data.caseDetail,
      });
    }, 1000);
  });
}
// 修改 测试数据文件 的是否默认
export function UpdateCaseDefault(params) {
  return request.post("/example/updateExampleDataDefault", params);

  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        code: 1,
        msg: "成功",
      });
    }, 1000);
  });
}
// 获取所有用例（用例树）
export function ObtainAllCaseTree(params) {
  return request.post("/example/getTestExampleListByType", params);
  // return new Promise((resolve, reject) => {
  //   setTimeout(() => {
  //     resolve({
  //       code:1,
  //       msg:"成功",
  //       data:_data.caseTree
  //     })
  //   }, 1000)
  // })
}
// 获取测试用例记录
export function GetTestCaseRecord(params) {
  return request.post("/record/queryTestRecordList", params);

  let list = JSON.parse(JSON.stringify(_data.testCaseRecord));
  if (param.state_id) {
    list = list.filter((item) => item.state_id == param.state_id);
  }
  if (param.result_id) {
    list = list.filter((item) => item.result_id == param.result_id);
  }
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        status: 0,
        info: list,
      });
    }, 2000);
  });
}
// 测试用例记录 详情
export function AdminRecordGetTestRecordInfo(params) {
  return request.post("/recordData/getTestRecordInfo", params);
}
// 停止执行用例
export function StopTestCase(params) {
  return request.get("/example/stopTestExampleByTaskId", { params });

  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        status: 0,
      });
    }, 2000);
  });
}
// 获取测试记录详情
export function GetTestRecordDetail(param) {
  const TestRecordDetail = JSON.parse(JSON.stringify(_data.testCaseChildren));
  TestRecordDetail.forEach((item) => {
    if (item.children && item.children.length) {
      item.children.forEach((child) => {
        child.caseDetail = JSON.parse(JSON.stringify(_data.caseDetail));
      });
    }
  });
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        status: 0,
        info: TestRecordDetail,
      });
    });
  });
}
export function GetTestRecordDetailList(param) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        list: _data.testCaseChildren[0].children,
        total: _data.testCaseChildren[0].children.length,
      });
    });
  });
}
// 获取详细报告
export function GetTestDetailReport(params) {
  // return request.post('/recordData/getTestRecordInfo',params)
  // return new Promise((resolve, reject) => {
  //   setTimeout(() => {
  //     resolve({
  //       'status': 0,
  //       'info': 'http://121.43.43.59/apiReport/?case=271'
  //     })
  //   })
  // })
}
// 通知后端 结束报告的进程
export function CloseOutReport(params) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        status: 0,
        info: null,
      });
    });
  });
}

// 用例信息同步
export function AdminSyncTestExampleListAndData(params) {
  return request.post("/example/syncTestExampleListAndData", params);
}
// 用例同步执行状态
export function AdminExampleCheckSyncStatus(params) {
  return request.get("/example/checkSyncStatus", { params });
}
// 批量执行测试用例
export function AdminExampleExecuteTestExampleBatch(params) {
  return request.post("/example/executeTestExampleBatch", params);
}
// 首页数据
export function AdminExampleStaticExampleByModuleType(params) {
  return request.post("/example/staticExampleByModuleType", { params });
}
